package com.sxpi.zixun.controller.resourcecategory;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxpi.zixun.bo.ResourceCategoryBo;
import com.sxpi.zixun.common.enums.ResultStatusEnum;
import com.sxpi.zixun.common.utils.fn.asserts.Vsserts;
import com.sxpi.zixun.controller.BaseController;
import com.sxpi.zixun.pojo.ResourceCategory;
import com.sxpi.zixun.service.resourcecategory.IResourceCategoryService;
import com.sxpi.zixun.vo.ResourceCategoryVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pug.generator.anno.PugDoc;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 董伟豪
 * @Date: 2022/9/2 19:22
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="资源分类",tabname="kss_resource_category")
public class ResourceCategoryController extends BaseController {

    private final IResourceCategoryService resourcecategoryService;

    /**
     * 查询资源分类列表信息
     * @return
     */
    @PostMapping("/resourcecategory/list")
    @PugDoc(name="查询资源分类列表信息")
    public List<ResourceCategoryBo> findResourceCategoryList() {
        return resourcecategoryService.findResourceCategoryList();
    }

    /**
     * 查询资源分类列表信息并分页
     * @param resourcecategoryVo
     * @return
     */
    @PostMapping("/resourcecategory/load")
    @PugDoc(name="查询资源分类列表信息并分页")
    public IPage<ResourceCategoryBo> findResourceCategorys(@RequestBody ResourceCategoryVo resourcecategoryVo) {
        return resourcecategoryService.findResourceCategoryPage(resourcecategoryVo);
    }

    /**
     * 根据资源分类id查询明细信息
     * @param id
     * @return
     */
    @PostMapping("/resourcecategory/get/{id}")
    @PugDoc(name="根据资源分类id查询明细信息")
    public ResourceCategoryBo getResourceCategoryById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return resourcecategoryService.getResourceCategoryById(new Long(id));
    }

    /**
     * 保存和修改资源分类
     * @param resourcecategory
     * @return
     */
    @PostMapping("/resourcecategory/saveupdate")
    @PugDoc(name="保存和修改资源分类")
    public ResourceCategoryBo saveUpdateResourceCategory(@RequestBody ResourceCategory resourcecategory) {
        return resourcecategoryService.saveUpdateResourceCategory(resourcecategory);
    }

    /**
     * 根据资源分类id删除资源分类
     * @param id
     * @return
     */
    @PostMapping("/resourcecategory/delete/{id}")
    @PugDoc(name="根据资源分类id删除资源分类")
    public int deleteResourceCategoryById(@PathVariable("id") String id) {
        Vsserts.isEmptyEx(id, ResultStatusEnum.ID_NOT_EMPTY);
        return resourcecategoryService.deleteResourceCategoryById(new Long(id));
    }

    /**
     * 根据id更改排序和相关信息
     * @param resourceCategory
     * @return
     */
    @PostMapping("/resourcecategory/update")
    @PugDoc(name="根据id更改排序和相关信息")
    public boolean updateRelation(@RequestBody ResourceCategory resourceCategory) {
        return resourcecategoryService.updateById(resourceCategory);
    }
}
